<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	pageContext.setAttribute("path", path);
	pageContext.setAttribute("basePath", basePath);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath %>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我的交易</title>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.js"></script>

<!-- Custom Theme files -->
<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<!--theme-style-->
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />	
<!--//theme-style-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Wedding Store Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- start menu -->
<script src="js/simpleCart.min.js"> </script>
<!-- start menu -->
<link href="css/memenu.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="js/memenu.js"></script>
<script>$(document).ready(function(){$(".memenu").memenu();});</script>	
<!-- /start menu -->
<script type="text/javascript">
function init(){
	var message = document.getElementById("message").value;
	if (message != null && message != "") {
		alert(message);
		document.getElementById("message").value="";
	}
}
window.addEventListener("load",init,false);
</script>
</head>
<body> 
	<jsp:include page="../common/header.jsp"></jsp:include>
<!---->
<input type="hidden" id="message" value="${message }">
<div class="checkout">	 
	 <div class="container">	
		 <ol class="breadcrumb">
		  <jsp:include page="../common/first.jsp"></jsp:include>
		  <li class="active">我的交易</li>
		 </ol>
		 <div class="col-md-9 product-price1" style="width: 100%">
			 <div class="check-out">			
				 <div class=" cart-items">
					 <h3>我的交易</h3>
					 <div class="in-check" >
						  <ul class="unit">
							<li style="width: 10%"><span>家教姓名</span></li>
							<li style="width: 10%"><span>家长姓名</span></li>		
							<li style="width: 8%"><span>时长</span></li>
							<li style="width: 9%"><span>总价</span></li>
							<li style="width: 18%"><span>交易时间</span></li>
							<li style="width: 16%"><span>家长评价</span></li>
							<li style="width: 16%"><span>家教评价</span></li>
							<li style="width: 9%"><span>状态</span></li>							
							<div class="clearfix"> </div>
						  </ul>
						  <c:forEach items="${listDeal }" var="deal">
						  		<ul class="cart-header">
									<li style="width: 10%"><span>${deal.teacher.tea_name }</span></li>
									<li style="width: 10%"><span>${deal.patriarch.pat_name }</span></li>
									<li style="width: 8%"><span>${deal.deal_time }小时</span></li>
									<li style="width: 9%"><span>${deal.deal_money }元</span></li>
									<li style="width: 18%"><span>${deal.deal_date }</span></li>
									<li style="width: 16%"><span onclick="patEvaluate(${deal.id},'${deal.pat_evaluate}')"><button class=" btn-primary " data-toggle="modal" data-target="#myModal_pat">点击查看详情</button></span></li>
									<li style="width: 16%"><span onclick="teaEvaluate(${deal.id},'${deal.tea_evaluate }')"><button class=" btn-primary " data-toggle="modal" data-target="#myModal_tea">点击查看详情</button></span></li>
									<li style="width: 9%">
										<c:choose>
											<c:when test="${not empty sessionScope.teacher }">
												<c:choose>
													<c:when test="${deal.deal_status eq 0}">
														<span onclick="accept(${deal.id})">点击接受</span>
														<span onclick="refuse(${deal.id})">点击拒绝</span>
													</c:when>
													<c:when test="${deal.deal_status eq 1}">
														<span onclick="finish(${deal.id})">进行中，点击确认完成</span>
													</c:when>
													<c:when test="${deal.deal_status eq 2}">
														<span>已完成</span>
													</c:when>
													<c:when test="${deal.deal_status eq 3}">
														<span>已拒绝</span>
													</c:when>
													<c:when test="${deal.deal_status eq 4}">
														<span>对方已取消</span>
													</c:when>
													<c:when test="${deal.deal_status eq 5}">
														<span>等待对方确认</span>
													</c:when>
												</c:choose>
											</c:when>
											<c:when test="${not empty sessionScope.patriarch }">
												<c:choose>
													<c:when test="${deal.deal_status eq 0}">
														<span onclick="cancel(${deal.id})">点击取消</span>
													</c:when>
													<c:when test="${deal.deal_status eq 1}">
														<span>进行中</span>
													</c:when>
													<c:when test="${deal.deal_status eq 2}">
														<span>已完成</span>
													</c:when>
													<c:when test="${deal.deal_status eq 3}">
														<span>已拒绝</span>
													</c:when>
													<c:when test="${deal.deal_status eq 4}">
														<span>已取消</span>
													</c:when>
													<c:when test="${deal.deal_status eq 5}">
														<span onclick="sureFinish(${deal.id})">点击确认对方完成</span>
													</c:when>
												</c:choose>
											</c:when>
										</c:choose>
									
									</li>
									<div class="clearfix"> </div>
								</ul>
						  </c:forEach>
						  <jsp:include page="../common/pages.jsp"></jsp:include>
					 </div>
				  </div>					  
			 </div>
		 </div>
	 </div>
</div>
<script type="text/javascript">
	function accept(id){
		var t = confirm("确认接受吗?");
		if (t) {
			$.post("deal/updateDeal",{deal_status:1,id:id},function(data){
	    		if (!data.meta.success) {
	    			alert("接受失败！");
	    		}else{
	    			alert("接受成功！");
	    			window.location.reload();
	    		}
		    });
		}
	}
	
	function sureFinish(id){
		var t = confirm("确认对方完成了吗?");
		if (t) {
			$.post("deal/updateDeal",{deal_status:2,id:id},function(data){
	    		if (!data.meta.success) {
	    			alert("确认失败！");
	    		}else{
	    			alert("确认成功！");
	    			window.location.reload();
	    		}
		    });
		}
	}
	
	function refuse(id){
		var t = confirm("确认拒绝吗?");
		if (t) {
			$.post("deal/updateDeal",{deal_status:3,id:id},function(data){
	    		if (!data.meta.success) {
	    			alert("拒绝失败！");
	    		}else{
	    			alert("拒绝成功！");
	    			window.location.reload();
	    		}
		    });
		}
	}
	
	function cancel(id){
		var t = confirm("确认取消吗?");
		if (t) {
			$.post("deal/updateDeal",{deal_status:4,id:id},function(data){
	    		if (!data.meta.success) {
	    			alert("取消失败！");
	    		}else{
	    			alert("取消成功！");
	    			window.location.reload();
	    		}
		    });
		}
	}
	
	function finish(id){
		var t = confirm("确认完成了吗?");
		if (t) {
			$.post("deal/updateDeal",{deal_status:5,id:id},function(data){
	    		if (!data.meta.success) {
	    			alert("完成失败！");
	    		}else{
	    			alert("完成成功！等待家长确认中...");
	    			window.location.reload();
	    		}
		    });
		}
	}
</script>
<script type="text/javascript">
	function patEvaluate(id,pat_evaluate){
		$("#pat_evaluate").val(pat_evaluate);
		$("#id1").val(id);
	}
	function teaEvaluate(id,tea_evaluate){
		$("#tea_evaluate").html(tea_evaluate);
		$("#id2").val(id);
	}
	
	function submitPatEvaluate(){
		var pat_evaluate = $("#pat_evaluate").val();
		var id1 = $("#id1").val();
		$.post("deal/updateDeal",{pat_evaluate:pat_evaluate,id:id1},function(data){
    		if (!data.meta.success) {
    			alert(data.meta.message);
    		}else{
    			alert("评价成功！");
    			window.location.reload();
    		}
	    });
	}
	function submitPTeaEvaluate(){
		var tea_evaluate = $("#tea_evaluate").val();
		var id2 = $("#id2").val();
		$.post("deal/updateDeal",{tea_evaluate:tea_evaluate,id:id2},function(data){
    		if (!data.meta.success) {
    			alert(data.meta.message);
    		}else{
    			alert("评价成功！");
    			window.location.reload();
    		}
	    });
	}

</script>
<!-- 家长评价家教 -->
<div class="modal fade" id="myModal_pat" tabindex="-1" role="dialog" aria-labelledby="myModalLabel_pat" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel_pat">家长评价</h4>
            </div>
            <form>
            	<input type="hidden" id="id1" name="id">
	            <div class="modal-body">
	            	<textarea id="pat_evaluate" name="pat_evaluate" style="border-color: rgba(162, 67, 67, 0);display: inline-block;border-top-width: 5px;height: 80px;width: 100%;"></textarea>
	            </div>
	            <c:choose>
	            	<c:when test="${not empty sessionScope.patriarch }">
	            		<div class="modal-footer">
			                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			                <input type="button" class="btn btn-primary" value="提交更改" onclick="submitPatEvaluate()">
			            </div>
	            	</c:when>
	            </c:choose>
            </form>
        </div>
    </div>
</div>
<!-- 家教评价家长 -->
<div class="modal fade" id="myModal_tea" tabindex="-1" role="dialog" aria-labelledby="myModalLabel_tea" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel_tea">家教评价</h4>
            </div>
            <form>
            	<input type="hidden" id="id2" name="id">
	            <div class="modal-body">
	            	<textarea id="tea_evaluate" name="tea_evaluate" style="border-color: rgba(162, 67, 67, 0);display: inline-block;border-top-width: 5px;height: 80px;width: 100%;"></textarea>
	            </div>
	            <c:choose>
	            	<c:when test="${not empty sessionScope.teacher }">
	            		<div class="modal-footer">
			                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			                <input type="button" class="btn btn-primary" value="提交更改" onclick="submitPTeaEvaluate()">
			            </div>
	            	</c:when>
	            </c:choose>
            </form>
        </div>
    </div>
</div>


<!---->
	<jsp:include page="../common/footer.jsp"></jsp:include>	 
</body>
</html>